package com.universal.schedule;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.universal.schedule.timetable.CourseModel;

public class ScheduleDetailActivity extends Activity {

	private TextView mTitle;
	private CourseModel mCourseModel;
	private ImageView mImageUpdate;
	private TextView mMessage;
	private TextView mName;
	private TextView mJie;
	private TextView mLocation;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_schedule_detail);
		initUI();
		findView();
		initData();
	}

	private void initData() {
		mTitle.setText(mCourseModel.getCourseName());
		mMessage.setText(mCourseModel.getCourseName());
		mName.setText(mCourseModel.getTeacherName());
		mJie.setText(mCourseModel.getSection()+"-"+(mCourseModel.getSection()+mCourseModel.getSectionSpan()-1)+"节");
		mLocation.setText(mCourseModel.getClassRoom());
		mImageUpdate.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ScheduleDetailActivity.this, UpdateScheduleActivity.class);
				intent.putExtra("schedule", mCourseModel);
				startActivityForResult(intent, 1001);
			}
		});
	}

	private void initUI() {
		mCourseModel = (CourseModel) getIntent().getSerializableExtra("schedule");
		
	}

	private void findView() {
		mTitle = (TextView) findViewById(R.id.title);
		mMessage = (TextView) findViewById(R.id.tv_message);
		mName = (TextView) findViewById(R.id.tv_name);
		mJie = (TextView) findViewById(R.id.tv_jie);
		mLocation = (TextView) findViewById(R.id.tv_location);
		mImageUpdate = (ImageView) findViewById(R.id.image_update);
		
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;

		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(null!=data){
			mCourseModel = (CourseModel) data.getSerializableExtra("schedule");
			mTitle.setText(mCourseModel.getCourseName());
			mMessage.setText(mCourseModel.getCourseName());
			mName.setText(mCourseModel.getTeacherName());
		}
		super.onActivityResult(requestCode, resultCode, data);
	}
}
